from common.constant import Constant
from domain.serializable import Serializable


class AppInfo(Serializable):
    def __init__(self):
        self.host = ''
        self.appid = ''
        self.appkey = ''
        self.channel: int = 2
        self.channelAlias = 'default'

    def to_header_request_stack(self):
        return [{
            Constant.TO_APPID_KEY: self.appid,
            Constant.TO_APPKEY_KEY: self.appkey,
            Constant.TO_CHANNEL_KEY: int(self.channel)
        }]

    @staticmethod
    def to_body_request_stack(appids):
        result = []
        if isinstance(appids, str):
            result.append({
                Constant.TO_APPID_KEY: appids,
                Constant.TO_CHANNEL_ALIAS_KEY: Constant.DEFAULT_CHANNEL_ALIAS
            })
        if isinstance(appids, (list, tuple)):
            for appid in appids:
                result.append({
                    Constant.TO_APPID_KEY: appid,
                    Constant.TO_CHANNEL_ALIAS_KEY: Constant.DEFAULT_CHANNEL_ALIAS
                })
        return result
